package com.youxin.dataStream.custormSource;

import org.apache.flink.streaming.api.functions.source.ParallelSourceFunction;

/**
 * 多并行度的source
 */
public class ParalleSource implements ParallelSourceFunction<Long>{

    private boolean flag = true;
    private Long num = 0L;

    /**
     * 持续输出数据的方法
     * @param sourceContext
     * @throws Exception
     */
    @Override
    public void run(SourceContext<Long> sourceContext) throws Exception {
        while(flag){
            sourceContext.collect(num++);
            Thread.sleep(1000);
        }
    }

    /**
     * 关闭程序的时候调用一次
     */
    @Override
    public void cancel() {
        flag = false;
    }
}
